<?php
/*
+--------------------------------------------------------------------------
|   AffiliStore 2
|   ========================================
|   Web: http://www.affilistore.com
|   Email: admin (at) affilistore (dot) com
|	License Type: AffiliStore 2 is NOT open source software and limitations apply 
|   Licence Info: Visit AffiliStore website and click on 'Licence'
+--------------------------------------------------------------------------
*/
if (eregi(".inc.php",$HTTP_SERVER_VARS['PHP_SELF']) || eregi(".inc.php",$_SERVER['PHP_SELF'])) {
	echo "<html>\r\n<head>\r\n<title>Forbidden 403</title>\r\n</head>\r\n<body><h3>Forbidden 403</h3>\r\nThe document you are requesting is forbidden.\r\n</body>\r\n</html>";
	exit;
}


$box_content = new XTemplate ("skins/".$configSkin['value']."/styleTemplates/subcategories.tpl");
		
		

$brandvalues = array();
$countbrands = 0;

/* create sub nav categories */
$getTotalDBs = mysql_query("SELECT value FROM affiliSt_config WHERE name = 'totalDBs'");
$totalDBs = mysql_fetch_assoc($getTotalDBs);
$totalnavs = $totalDBs['value'];
$prevpieces = array();
for ($n=1;$n<=$totalnavs;$n++) {
$getNewNav = mysql_query("SELECT value FROM affiliSt_config WHERE name = 'nav$n'");
$newNav = mysql_fetch_assoc($getNewNav);
	if ($newNav['value'] != NULL) {
	$pieces = explode("-:-", $newNav['value']);
	$navarray = array_merge($prevpieces, $pieces);
	$prevpieces = $navarray;
	}
}
//$navarray = '';
if (is_array($navarray)) {
sort($navarray);



//print_r($navarray);exit;
//unset($prevspieces);
//print_r($prevspieces[0]);exit;

$total = count($navarray);
$counter = 0;
	for ($i=0;$i<$total;$i++) {
	$spieces = explode("(:)", $navarray[$i]);
		if ($spieces[0] == $uniquepieces[$counter-1][0]) {
		$counter = $counter - 1;
		$uniquepieces[$counter] = array_unique(array_merge($spieces, $uniquepieces[$counter]));
//print_r($uniquepieces);echo $i; echo $counter;
		} else {
		$uniquepieces[$counter] = $spieces;
//print_r($uniquepieces);echo $i; echo $counter;
		}
	$counter++;
	//$prevspieces = $spieces;
	}
//exit;

//print_r($uniquepieces);exit;



$total = count($uniquepieces);
	for ($u=0;$u<$total;$u++) {
		if ($uniquepieces[$u][0] == str_replace("-", " ", $_GET['pc'])) {
		unset($uniquepieces[$u][0]);
		//$uniquepieces[$u] = '';
			if (is_array($uniquepieces[$u])) {
			sort($uniquepieces[$u]);
			$stotal = count($uniquepieces[$u]);
				if ($stotal > 0) {
					for ($sl=0; $sl<$stotal; $sl++) {
						if ($uniquepieces[$u][$sl] == str_replace("-", " ", $_GET['pb'])) {
						$brandvalueonoff[$sl] = 'brandNavOn';
						} else {
						$brandvalueonoff[$sl] = 'brandNavOff';
						}		
						if ($navOpt[7] == 1) {
						// html perma
						$brandlinkvalues[$sl] = $installDir['value'].'subproducts/'.str_replace(" ", "-", $_GET['pc']).'/'.str_replace(" ", "-", $uniquepieces[$u][$sl]).'.html';
						} else {
						// php link
						$brandlinkvalues[$sl] = $installDir['value'].'index.php?case=subproducts&pc='.str_replace(" ", "+", $_GET['pc']).'&pb='.str_replace(" ", "+", $uniquepieces[$u][$sl]);
						}
							
					$brandvalues[$sl] = $uniquepieces[$u][$sl];
					$countbrands++;
					}
				}
			}
		}
	}
// end new subnav
		
	if ($brandvalues[0] != NULL) {
			
		$tdtotal = $countbrands/4;
		$tdtotal = ceil($tdtotal);
			
		$counter = 0;
			for ($i=0; $i<$countbrands; $i++) {
					$box_content->assign("SUBFONTSTYLE",$brandvalueonoff[$i]);
					$box_content->assign("SUBLINKDATA",$brandlinkvalues[$i]);
					$box_content->assign("SUBDATA",$brandvalues[$i]);
						if ($counter == 0) {
						$box_content->assign("OPENBRANDTD",'<td align="left" valign="top">');
						$box_content->assign("CLOSEBRANDTD",'');
						$box_content->assign("CLOSEBRANDENDTD",'');
						} else if ($counter == $tdtotal) {
						$box_content->assign("OPENBRANDTD",'<td align="left" valign="top">');
						$box_content->assign("CLOSEBRANDTD",'</td>');
						$box_content->assign("CLOSEBRANDENDTD",'');
						$counter = 0;
						} else if ($i == $countbrands) {
						$box_content->assign("OPENBRANDTD",'');
						$box_content->assign("CLOSEBRANDTD",'');
						$box_content->assign("CLOSEBRANDENDTD",'</td>');
						$counter = 0;
						} else {
						$box_content->assign("OPENBRANDTD",'');
						$box_content->assign("CLOSEBRANDTD",'');
						}
					$counter++;
					$box_content->parse("subcategories.li");
			}
	
	
				
	$box_content->assign("TITLE",'Refine Search');
	$box_content->assign("SKIN",$configSkin['value']);
	$box_content->parse("subcategories");
	$box_content = $box_content->text("subcategories");
	} else {
	$box_content->parse("nosubcategories");
	$box_content = $box_content->text("nosubcategories");
	}
}
?>